package com.sfeir.tv.client.mvc.framework.impl.gwt;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Composite;
import com.sfeir.tv.client.mvc.framework.AppEventListener;
import com.sfeir.tv.client.mvc.framework.Controller;
import com.sfeir.tv.client.mvc.framework.Model;
import com.sfeir.tv.client.mvc.framework.View;

public abstract class GWTView extends Composite implements View
{
	protected String id;
	protected Controller controller;
	protected Map/*<String, GWTView>*/ children = new HashMap/*<String, GWTView>*/();

	public GWTView(String id) {
		this.id = id;
	}
	
	public Controller getController() {
		return controller;
	}

	public void setController(Controller controller) {
		this.controller = controller;
	}

	/**
	 * refresh the view with the model
	 * @param model
	 */
	public abstract void refreshView(Model model);

	/**
	 * add a GUI component to the view
	 * @param guiComponent the GUI component
	 * @param xPos the top left corner position
	 * @param yPos the top left corner position
	 */
	public abstract void addComponent(Object guiComponent, int xPos, int yPos);
	
	public abstract void addComponent(Object guiComponent);

	/**
	 * send the event to the controller
	 * @param event
	 */
	public abstract void fireEvent(int eventType);
	
//	public abstract Object getComponent();

	/**
	 * Should be abstract
	 */
    public void register(int eventType, AppEventListener listener)
    {
        this.controller.register( eventType, listener );
    }
    
    public abstract void onGWTBrowserEvent( Event event );
    
    public View getChild(String id) {
    	return (View) children.get(id);
    }
    
    public String getId() {
    	return id;
    }
    
    public void putChildInMap(String uniqueID, View view) {
    	children.put(uniqueID, view);
    }

}